import 'package:flutter/material.dart';
import 'package:flutter_test_1/colors.dart';
import 'package:flutter_test_1/ex_widget.dart';
import 'package:flutter_test_1/just_test_text.dart';

class AnimationTestView extends StatefulWidget {
  const AnimationTestView({super.key});

  @override
  State<AnimationTestView> createState() => _AnimationTestViewState();
}

class _AnimationTestViewState extends State<AnimationTestView> with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<Offset> _animation;

  @override
  void initState() {
    super.initState();

    // 创建动画控制器
    _controller = AnimationController(
      duration: Duration(seconds: 2),
      vsync: this,
    );

    // 创建 Tween，将值范围映射到 0.0 - 1.0
    // _animation = Tween<double>(begin: 0.0, end: 1.0).animate(_controller);

    _animation = Tween<Offset>(
      begin: Offset(0, 0),
      end: Offset(1, 1),
    ).animate(CurvedAnimation(parent: _controller, curve: Curves.linear));

    // 启动动画
    // _controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Animation Example'),
      ),
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
                onPressed: () {
                  print("have click btn");
                  _controller.forward();
                },
                child: JustTestText("test")),

            // FadeTransition(
            //   opacity: _animation,
            //   child: Container(
            //     width: 200,
            //     height: 200,
            //     color: Colors.blue,
            //     child: const Center(
            //       child: Text(
            //         'Animated Widget',
            //         style: TextStyle(color: Colors.white),
            //       ),
            //     ),
            //   ),
            // ),

            SlideTransition(
              position: _animation,
              child: Container(
                width: 50,
                height: 50,
                color: Colors.blue,
                child: const Center(
                  child: Text(
                    'Animated Widget',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
            )
          ],
        ).backgroundColor(AppColors.testColor1),
      ),
    );
  }

  @override
  void dispose() {
    // 销毁动画控制器
    _controller.dispose();
    super.dispose();
  }
}
